package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbCitiesMapper;
import com.bw1806.pojo.TbCities;
import com.bw1806.pojo.TbCitiesExample;
import com.bw1806.sellergoods.service.TbCitiesService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbCitiesServiceImpl implements TbCitiesService {

    @Autowired
    private TbCitiesMapper tbCitiesMapper;

    @Override
    public List<TbCities> findAll() {
        return tbCitiesMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbCities> pagelist(TbCities tbCities,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbCitiesExample example=new TbCitiesExample();

        TbCitiesExample.Criteria criteria = example.createCriteria();

        if(tbCities!=null){
            //if(tbCities.getName()!=null && tbCities.getName().length()>0){
            //    criteria.andNameLike("%"+tbCities.getName()+"%");
           // }
        }

        Page<TbCities> page= (Page<TbCities>) tbCitiesMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbCities tbCities) {
        Long id = tbCities.getId();
        if(id != null && id !=0){
            tbCitiesMapper.updateByPrimaryKey(tbCities);
        } else{
            tbCitiesMapper.insert(tbCities);
        }
    }

    @Override
    public TbCities getById(Long id) {
        return tbCitiesMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbCitiesMapper.deleteByPrimaryKey(id);
        }
        //tbCitiesMapper.deletebth(ids);
    }
}
